import pymongo
from pymongo import MongoClient
import datetime
from bson import BSON

client=None
db=None

def connect(ip) :  #def
	global client
	client = MongoClient(ip, 27017)
	print 'connected.'

connect('140.112.170.32') #call for test

def getdb(db_name) :
	global db
	db = client[db_name]
	print "get database : %s" %(db_name)

getdb('test-database')

def getcollection(col_name) :
	collection = db[col_name]
	print "get collection : %s" %(col_name)
	return 19

getcollection('test-collection')


### def storage schema
def write_bson() : #instead of JSON, is it protobuf? #it seems like it will sort title automatically??
	bson_string = BSON.encode({"Type": "IR",
		"ActionType": "action",
		"dimension": "1",
		"value": 186,
		"values":"NA"
		})
	print bson_string.decode()

def def_schema() : #with id by itself?
	post = {"house_id": "B.L. 7F",
	"location": "My first blog post!",  #should be a index
	"timestamp": datetime.datetime.utcnow(),
	"data" : write_bson()
	}
	print 'def a schema'

def_schema()


